import BlogLayout from "@/components/layout/BlogLayout";
import type { Route } from "@/types/blog";
import { notFound } from "next/navigation";

interface StackLayoutProps {
  children: React.ReactNode;
  params: Promise<{
    stack: string;
  }>;
}

export default async function StackLayout({ 
  children, 
  params 
}: StackLayoutProps) {
  // const { stack, category, slug } = await params;
  const { stack } = await params;
  const kebabToPascalCase = (str:string) => str.split('-').map(word => word[0].toUpperCase() + word.slice(1)).join('');
  
  try {
    const { routes }: {routes: Route[]} = await import(`@/routes/${stack}/routes.tsx`);

    return (
      <BlogLayout
          routes={routes}
          title={kebabToPascalCase(stack)}
          logo={`/${stack}.svg`}
        >
        {children}
      </BlogLayout>
    );
  } catch {
    notFound();
  }

}